using UnityEngine;
using QFramework;
using QAssetBundle;

// 1.请在菜单 编辑器扩展/Namespace Settings 里设置命名空间
// 2.命名空间更改后，生成代码之后，需要把逻辑代码文件（非 Designer）的命名空间手动更改
namespace QFramework.Example
{
	public partial class AllExp : ViewController
	{
		void Start()
		{
			// Code Here
		}

        private void OnTriggerEnter2D(Collider2D collision)
        {
            if(collision.GetComponent<CollectableArea>())
            {
                AudioKit.PlaySound(Sfx.ALLEXP);
                var allExps = FindObjectsByType<Exp>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
                foreach (var item in allExps)
                {
                    ActionKit.OnFixedUpdate.Register(() =>
                    {
                        Vector3 dirction = Player.Default.transform.position - item.transform.position;

                        item.transform.Translate(dirction * Time.deltaTime * 4);

                    }).UnRegisterWhenGameObjectDestroyed(item.gameObject);
                }
                var allCoins = FindObjectsByType<Coin>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
                foreach (var item in allCoins)
                {
                    ActionKit.OnFixedUpdate.Register(() =>
                    {
                        Vector3 dirction = Player.Default.transform.position - item.transform.position;

                        item.transform.Translate(dirction * Time.deltaTime * 4);

                    }).UnRegisterWhenGameObjectDestroyed(item.gameObject);
                }
                this.DestroyGameObjGracefully();
            }
        }
    }
}
